package org.stone.project;

import reactor.core.publisher.Mono;
import reactor.netty.DisposableServer;
import reactor.netty.tcp.TcpServer;

import java.io.UnsupportedEncodingException;
import java.net.InetSocketAddress;
import java.net.SocketAddress;
import java.util.function.Supplier;

public class Demo2 {
    public static void main(String[] args) throws UnsupportedEncodingException, InterruptedException {
        TcpServer tcpServer = TcpServer.create();
        Supplier<? extends SocketAddress> param = new Supplier<SocketAddress>() {
            @Override
            public SocketAddress get() {
                return new InetSocketAddress(8089);
            }
        };


        String str = "你好";


        Mono<? extends DisposableServer> bind = tcpServer
                .doOnConnection(con->{
                    System.out.println("连接了");
                })
                .handle((in, out) -> {
                    return out.sendString(Mono.just(str));
                })
                .bindAddress(param)
                .bind();
        bind.subscribe();

        Thread.currentThread().join();
    }
}
